package com.ia.bikerecife.database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

public class Banco
{
    private Connection connect   = null;
    private Statement  statement = null;
    private ResultSet  resultSet = null;

    public Banco() throws Exception
    {
        Class.forName("com.mysql.jdbc.Driver");
        connect = DriverManager.getConnection("jdbc:mysql://localhost/projetoia?" + "user=root&password=");
        statement = connect.createStatement();
    }

    public ArrayList<String> consultarPerguntas(String query, String[] params) throws Exception
    {
        resultSet = statement.executeQuery(query);

        ArrayList<String> list = new ArrayList<String>();
        while (resultSet.next())
        {
            if (params.length > 1)
            {
                for (int i = 0; i < params.length; i++)
                {
                    list.add(resultSet.getString(params[i]));
                }
            }
            else
            {
                list.add(resultSet.getString(params[0]));
            }
        }

        return list;
    }

    public String consultar(String lugar) throws Exception
    {
        resultSet = statement.executeQuery(lugar);
        resultSet.next();
        String resposta = resultSet.getString("descricao");
        return resposta;
    }

}
